<!DOCTYPE html	PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui"
	template="/template/template_layout_lrt.xhtml"
	xmlns:s="http://sduept.security.el/func">
	<ui:define name="head">
		<style>
.ui-button, .ui-button span, button.ui-button.ui-state-default span,
	.ui-button.ui-state-default span {
	font-weight: normal
}
</style>
	</ui:define>
	<ui:define name="top-box-tools" >
		<h:form id="btnForm">
			<p:confirmDialog global="true" showEffect="fade" hideEffect="fade">
				<p:commandButton value="是" type="button"
					styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
				<p:commandButton value="否" type="button"
					styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
			</p:confirmDialog>
			<p:growl id="msgs" showDetail="true" />
			<p:toolbar id="btnBar" rendered="#{s:hasPermission(session,'xtsz_xtqx_jsgl_xj') or
			s:hasPermission(session,'xtsz_xtqx_jsgl_bj') or
			s:hasPermission(session,'xtsz_xtqx_jsgl_sc') or
			s:hasPermission(session,'xtsz_xtqx_jsgl_sq')}">
				<f:facet name="left" >
					<p:commandButton value="新建" id="newBtn" icon="ui-icon-document"
						rendered="#{s:hasPermission(session,'xtsz_xtqx_jsgl_xj')}"
						actionListener="#{roleFunctionController.preCreate}"
						update=":roleForm:rolepg" style="margin-left: 3px;"
						oncomplete="PF('newDialog').show()" />
					<p:commandButton value="编辑" id="editBtn" icon="ui-icon-pencil"
						rendered="#{s:hasPermission(session,'xtsz_xtqx_jsgl_bj')}"
						disabled="#{roleFunctionController.currentSelectRole == null}"
						update=":roleForm:rolepg" oncomplete="PF('newDialog').show()"
						style="margin-left: 3px;" />
					<p:commandButton value="删除" id="deleteBtn" icon="ui-icon-trash"
						rendered="#{s:hasPermission(session,'xtsz_xtqx_jsgl_sc')}"
						disabled="#{roleFunctionController.currentSelectRole == null}"
						actionListener="#{roleFunctionController.delete}"
						update=":leftForm:role msgs editBtn savebtn @this rightForm:treeTable"
						style="margin-left: 3px; margin-right:8px">
						<p:confirm header="提示" message="您确定要删除该角色吗？删除后该角色将不可用！"
							icon="ui-icon-alert" />
					</p:commandButton>
					<!-- <span class="ui-separator"> <span
						class="ui-icon ui-icon-grip-dotted-vertical" />
					</span> -->
					<p:commandButton icon="fa fa-hand-paper-o" value="授权" id="savebtn"
						rendered="#{s:hasPermission(session,'xtsz_xtqx_jsgl_sq')}"
						update="rightForm:treeTable grantPermissionForm:treeTable"
						actionListener="#{roleFunctionController.preGrantPermission()}"
						style="font-weight:normal;margin-left:8px"
						disabled="#{roleFunctionController.currentSelectRole == null}"
						oncomplete="PF('grantPermissionDialog').show()"/>
				</f:facet>
			</p:toolbar>
		</h:form>
	</ui:define>
	<ui:define name="left-box-title">
		&nbsp;角色列表
	</ui:define>
	<ui:define name="left-box-body">
		<h:form id="leftForm">
			<p:dataTable id="role" var="role" emptyMessage="无数据"
				value="#{roleFunctionController.roles}" selectionMode="single"
				rowKey="#{role.id}">
				<p:ajax event="rowSelect"
					listener="#{roleFunctionController.onRowSelect}"
					update="btnForm:savebtn rightForm:treeTable btnForm:msgs :btnForm:editBtn :btnForm:deleteBtn" />
				<p:ajax event="rowUnselect"
					listener="#{roleFunctionController.onRowUnselect}"
					update="btnForm:savebtn rightForm:treeTable :btnForm:editBtn :btnForm:deleteBtn" />
				<p:column headerText="序号" style="width:15%;text-align:center">
					<h:outputText value="#{roleFunctionController.getIndex(role)}" />
				</p:column>
				<p:column headerText="名称">
					<h:outputText value="#{role.name}" />
				</p:column>
				<p:column headerText="描述">
					<h:outputText value="#{role.description}" />
				</p:column>
			</p:dataTable>
		</h:form>
	</ui:define>
	<ui:define name="right-box-title">
		所属权限
	</ui:define>
	<ui:define name="right-box-body">
		<h:form id="rightForm">
			<p:treeTable id="treeTable" widgetVar="treeTable" emptyMessage="无数据"
				value="#{roleFunctionController.root}" var="fun">
				<p:column headerText="名称">
					<h:outputText value="#{fun.function.name } " />
				</p:column>

				<p:column headerText="权限" style="text-align:center;width:15%">
					<h:outputText rendered="#{fun.permission=='DENY'}"
						style="color:red" value="拒绝" />
					<h:outputText rendered="#{fun.permission=='ALLOW'}"
						style="color:green" value="允许" />
				</p:column>

				<p:column headerText="类型" style="text-align:center">
					<h:outputText value="页面" styleClass="fa fa-home"
						rendered="#{fun.function.type.equals('page')}" style="color:#433" />
					<h:outputText value=" 页内菜单" styleClass="fa fa-dot-circle-o"
						rendered="#{fun.function.type.equals('pagemenu')}"
						style="color:#CD2990" />
					<h:outputText value=" 菜单" styleClass="fa fa-bars"
						rendered="#{fun.function.type.equals('menu')}"
						style="color:#006400" />
					<h:outputText value=" 操作" styleClass="fa fa-wrench"
						rendered="#{fun.function.type.equals('operation')}"
						style="color:blue" />
				</p:column>
			</p:treeTable>
		</h:form>
		<p:dialog widgetVar="grantPermissionDialog" id="grantPermissionDialog"
			resizable="false" header="授权管理" modal="true" width="800" height="600">
			<h:form id="grantPermissionForm">
				<p:toolbar>
					<f:facet name="left">
						<p:commandButton value="保存" process="@this"
							actionListener="#{roleFunctionController.save()}"
							update="rightForm:treeTable btnForm:msgs"
							oncomplete="PF('grantPermissionDialog').hide()"
							styleClass="margin-left:10px" />
					</f:facet>
				</p:toolbar>
				<p:treeTable id="treeTable" widgetVar="treeTable" scrollHeight="500" style="margin-top:6px" selection="#{roleFunctionController.currentNode}"
					selectionMode="single" value="#{roleFunctionController.grantRoot}" scrollable="true" var="fun">
					<p:column headerText="名称" style="width:30%">
						<h:outputText value="#{fun.function.name} " />
					</p:column>
					<p:column headerText="类型" style="text-align:center;width:10%">
						<h:outputText value="页面" styleClass="fa fa-home"
							rendered="#{fun.function.type.equals('page')}" style="color:#433" />
						<h:outputText value=" 页内菜单" styleClass="fa fa-dot-circle-o"
							rendered="#{fun.function.type.equals('pagemenu')}"
							style="color:#CD2990" />
						<h:outputText value=" 菜单" styleClass="fa fa-bars"
							rendered="#{fun.function.type.equals('menu')}"
							style="color:#006400" />
						<h:outputText value=" 操作" styleClass="fa fa-wrench"
							rendered="#{fun.function.type.equals('operation')}"
							style="color:blue" />
					</p:column>
					<p:column headerText="权限" value="#{fun.permission}"
						style="padding:0px;width:25%">
						<p:selectOneRadio rendered="#{!fun.function.type.equals('root') &amp;&amp; !fun.function.type.equals('approot')}"
							value="#{fun.permission}" style="padding:0;margin:0" valueChangeListener="#{roleFunctionController.valueChange(fun)}">
							<p:ajax event="click" update="treeTable"
								listener="#{roleFunctionController.changeRadio}" >
							</p:ajax>
							<f:selectItem itemLabel="允许" itemValue="ALLOW" />
							<f:selectItem itemLabel="拒绝" itemValue="DENY" />
							<f:selectItem itemLabel="无" itemValue="" />
						</p:selectOneRadio>
					</p:column>
				</p:treeTable>
			</h:form>
		</p:dialog>

		<p:dialog widgetVar="newDialog" id="newDialog" header="新建角色"
			modal="true" width="600" height="300">
			<h:form id="roleForm">
				<p:toolbar>
					<f:facet name="left">
						<p:commandButton value="保存" icon="ui-icon-disk"
							oncomplete="PF('newDialog').hide()"
							actionListener="#{roleFunctionController.saveRole()}"
							update=":leftForm:role :btnForm:editBtn :btnForm:deleteBtn :btnForm:msgs :btnForm:savebtn" />
					</f:facet>
				</p:toolbar>
				<p:panelGrid columns="2" id="rolepg"
					style="margin-top:10px; width:100%;border:0">
					<h:outputText value="角色名称" />
					<p:inputText
						value="#{roleFunctionController.currentSelectRole.name}"
						style="width:100%" />
					<h:outputText value="角色描述" />
					<p:inputTextarea
						value="#{roleFunctionController.currentSelectRole.description}"
						style="width:100%" />
				</p:panelGrid>
			</h:form>
		</p:dialog>
	</ui:define>
	<ui:define name="contentend">
		<script>
			/* function exchangeScroll(){
				document.getElementById("rightForm:treeTable").removeEventListener('DOMMouseScroll', scrollFunc);
				$('grantPermissionForm:treeTable').focus();
			} */
		</script>
	</ui:define>
		
</ui:composition>